/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('retailir', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateTaskRequest {
  appkey?: string(name='Appkey', example='UP**********'),
  imageLeftBottom?: string(name='ImageLeftBottom', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  imageLeftTop?: string(name='ImageLeftTop', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  imageList?: [ 
    {
      fileLink?: string(name='FileLink'),
      xaxis?: int32(name='Xaxis'),
      yaxis?: int32(name='Yaxis'),
    }
  ](name='ImageList'),
  imageMiddleBottom?: string(name='ImageMiddleBottom', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  imageMiddleTop?: string(name='ImageMiddleTop', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  imageRightBottom?: string(name='ImageRightBottom', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  imageRightTop?: string(name='ImageRightTop', example='http://nls.alicdn.com/vision/shelf/testdata/case001/0.jpg'),
  taskName?: string(name='TaskName', example='taskName'),
}

model CreateTaskResponseBody = {
  requestId?: string(name='RequestId', example='20@312b8e21-6190-4850-a99e-9a600cf88517'),
  resultCode?: int32(name='ResultCode', example='0'),
  resultMessage?: string(name='ResultMessage', example='success'),
  task?: {
    appkey?: string(name='Appkey', example='UP**********'),
    jobId?: string(name='JobId', example='9a600cf885179a600cf88517'),
    namespace?: string(name='Namespace', example='ShelfInsight'),
    progress?: int32(name='Progress', example='23'),
    request?: string(name='Request', example='{""}'),
    status?: string(name='Status', example='0'),
    userId?: string(name='UserId', example='111111'),
    version?: string(name='Version'),
  }(name='Task'),
}

model CreateTaskResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateTaskResponseBody(name='body'),
}

async function createTaskWithOptions(request: CreateTaskRequest, runtime: Util.RuntimeOptions): CreateTaskResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appkey)) {
    query['Appkey'] = request.appkey;
  }
  if (!Util.isUnset(request.imageLeftBottom)) {
    query['ImageLeftBottom'] = request.imageLeftBottom;
  }
  if (!Util.isUnset(request.imageLeftTop)) {
    query['ImageLeftTop'] = request.imageLeftTop;
  }
  if (!Util.isUnset(request.imageList)) {
    query['ImageList'] = request.imageList;
  }
  if (!Util.isUnset(request.imageMiddleBottom)) {
    query['ImageMiddleBottom'] = request.imageMiddleBottom;
  }
  if (!Util.isUnset(request.imageMiddleTop)) {
    query['ImageMiddleTop'] = request.imageMiddleTop;
  }
  if (!Util.isUnset(request.imageRightBottom)) {
    query['ImageRightBottom'] = request.imageRightBottom;
  }
  if (!Util.isUnset(request.imageRightTop)) {
    query['ImageRightTop'] = request.imageRightTop;
  }
  if (!Util.isUnset(request.taskName)) {
    query['TaskName'] = request.taskName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateTask',
    version = '2019-09-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createTask(request: CreateTaskRequest): CreateTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return createTaskWithOptions(request, runtime);
}

model GetTaskRequest {
  appkey?: string(name='Appkey', example='To************'),
  jobId?: string(name='JobId', example='JobId'),
}

model GetTaskResponseBody = {
  requestId?: string(name='RequestId', example='20@312b8e21-6190-4850-a99e-9a600cf88517'),
  resultCode?: string(name='ResultCode', example='0'),
  resultMessage?: string(name='ResultMessage', example='success'),
  task?: {
    appkey?: string(name='Appkey', example='To************'),
    createTime?: long(name='CreateTime', example='123243424'),
    jobId?: string(name='JobId', example='4ad0e26847da4de9a842baa9765b652e'),
    lastUpdateTime?: long(name='LastUpdateTime', example='123243424'),
    namespace?: string(name='Namespace', example='ShelfInsight'),
    progress?: int32(name='Progress', example='23'),
    request?: string(name='Request', example='{""}'),
    response?: string(name='Response', example='“”'),
    status?: string(name='Status', example='COMPLETED'),
    statusCode?: string(name='StatusCode', example='40000003'),
    statusMessage?: string(name='StatusMessage', example='"Parameter invalid!"'),
    userId?: string(name='UserId', example='1122668997700980'),
    version?: int32(name='Version', example='0'),
  }(name='Task'),
}

model GetTaskResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetTaskResponseBody(name='body'),
}

async function getTaskWithOptions(request: GetTaskRequest, runtime: Util.RuntimeOptions): GetTaskResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appkey)) {
    query['Appkey'] = request.appkey;
  }
  if (!Util.isUnset(request.jobId)) {
    query['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTask',
    version = '2019-09-06',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTask(request: GetTaskRequest): GetTaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTaskWithOptions(request, runtime);
}

